﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using GalaSoft.MvvmLight.Messaging;
using ShoppingList.Helpers;
using System.Windows.Data;
namespace ShoppingList.Views
{
    public partial class ProductsView : PhoneApplicationPage
    {
        public ProductsView()
        {
            
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ProductsView_Loaded);


            TxtProductName.TextChanged += new TextChangedEventHandler(TxtProductName_TextChanged);
            TxtProductName.GotFocus += new RoutedEventHandler(TxtProductName_GotFocus);
            TxtProductName.LostFocus += new RoutedEventHandler(TxtProductName_LostFocus);
            Messenger.Default.Register<string>(this,"PRODUCTANIMATIONS_TOKEN", s =>
            {
                if (s == "ShowProducts")
                {
                    VisualStateManager.GoToState(this, "ShowProducts", true);
                }
                if(s== "ShowNewProduct")
                {
                    VisualStateManager.GoToState(this, "ShowNewProduct", true);

                  
                    
          

                }
             
            
            });
        }

        void TxtProductName_LostFocus(object sender, RoutedEventArgs e)
        {
            this.btnBarAddButton.IsEnabled = false;
            this.BtnSaveButton.IsEnabled = true;
            this.BtnSaveButton.IsEnabled = true;
        }

        void TxtProductName_GotFocus(object sender, RoutedEventArgs e)
        {
            this.btnBarAddButton.IsEnabled = false;
            this.BtnSaveButton.IsEnabled = false;
            this.BtnBarCancelButton.IsEnabled = false;
        }

        void TxtProductName_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox textBox = sender as TextBox;
             //Update the binding source 
            BindingExpression bindingExpr = textBox.GetBindingExpression(TextBox.TextProperty);
            bindingExpr.UpdateSource(); 

        }

        void ProductsView_Loaded(object sender, RoutedEventArgs e)
        {
            //trexStoryboard.Begin();
        }

       
    }
}